package com.aosgame;

import android.graphics.Bitmap;
import android.graphics.Rect;

import com.androidgame.fx.Graphics;
import com.androidgame.fx.ScreenConfig;

public class Map {

	public Bitmap		image;
	public Rect			screenRect;
	public Entity		focus;
	public static int	width;
	public static int	height;
	public int 			scrWidth;
	public int 			scrHeight;
	
	public Map(Bitmap image) {
		this.image = image;
		screenRect = new Rect();
		focus = null;
		width = image.getWidth();
		height = image.getHeight();
		scrWidth = ScreenConfig.virtualScreenWidth;
		scrHeight = ScreenConfig.virtualScreenHeight;
	}
	
	public void setFocus(Entity focus) {
		this.focus = focus;
	}
	
	public void update() {
		int left = 0;
		int top = 0;
		
		if(focus.position.x < scrWidth / 2) {
			left = 0;
		} else if(focus.position.x > width - scrWidth / 2) {
			left = width - scrWidth;
		} else {
			left = focus.position.x - scrWidth / 2;
		}
		
		if(focus.position.y < scrHeight / 2) {
			top = 0;
		} else if(focus.position.y > height - scrHeight / 2) {
			top = height - scrHeight;
		} else {
			top = focus.position.y - scrHeight / 2;
		}
		
		screenRect.set(left, top, left + scrWidth, top + scrHeight);
	}
	
	public void present(Graphics g) {
		if(focus == null) {
			g.drawBitmap(image, 0, 0);
		} else {
			g.drawBitmap(image, 0, 0, screenRect.left, screenRect.top, scrWidth, scrHeight);
		}
	}
}
